home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 January / PCWorld_2007-01_cd.bin / v cisle / autoit / autoit-v3.2.0.1-setup.exe / Examples / Helpfile / ObjEvent.au3 < prev    next >
Text File  |  2006-06-28  |  2KB  |  56 lines

  1. ; ObjEvent example
  2.  
  3. $oIE=ObjCreate("InternetExplorer.Application.1")       ; Create Internet Explorer application
  4. $SinkObject=ObjEvent($oIE,"IEEvent_","DWebBrowserEvents2") ; Assign events to UDFs starting with IEEvent_
  5.  
  6. ; Do some browsing activities
  7. $oIE.Visible=1
  8. $oIE.RegisterAsDropTarget = 1
  9. $oIE.RegisterAsBrowser = 1
  10. $oIE.Navigate( "http://www.AutoItScript.com/" )
  11.  
  12. sleep(3000)            ; Give it time to load the web page
  13.  
  14. $SinkObject=0            ; Stop IE Events
  15. $oIE.Quit            ; Quit IE
  16. $oIE=0
  17. exit
  18.  
  19. ; one of many Internet Explorer Event Functions
  20.  
  21. Func IEEvent_ProgressChange($Progress,$ProgressMax)
  22.  
  23.    ProgressSet ( ($Progress * 100) / $ProgressMax , ($Progress * 100) / $ProgressMax & " percent to go." , "loading web page" )
  24.  
  25. EndFunc
  26.  
  27. Exit
  28.  
  29. ; COM Error Handler example
  30. ; ------------------------- 
  31.  
  32. $oIE=ObjCreate("InternetExplorer.Application.1")    ; Create Internet Explorer application
  33. $oMyError = ObjEvent("AutoIt.Error","MyErrFunc")    ; Initialize a COM error handler
  34.  
  35. $oIE.UnknownMethod        ; Deliberately call an undefined method
  36.  
  37. If @error then
  38.   Msgbox (0,"AutoItCOM test","Test passed: We got an error number: " & @error)
  39. Else
  40.   Msgbox (0,"AutoItCOM test","Test failed!")
  41. Endif
  42.  
  43. Exit
  44.  
  45. ; This is my custom defined error handler
  46. Func MyErrFunc()
  47.  
  48.   $HexNumber=hex($oMyError.number,8)    ; for displaying purposes
  49.   Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !"       & @CRLF  & @CRLF & _
  50.              "err.description is: "    & @TAB & $oMyError.description    & @CRLF & _
  51.              "err.number is: "         & @TAB & $HexNumber              & @CRLF & _
  52.              "err.scriptline is: "     & @TAB & $oMyError.scriptline     & @CRLF _
  53.             )
  54.   SetError(1)  ; to check for after this function returns
  55. Endfunc
  56.